import 'package:flutter/material.dart';
import 'package:flutter_app/BaseMaterialWidget.dart';

class FormLoginTest extends BaseMaterialWidget {
  String username;
  String pwd;

  GlobalKey<FormState> loginKey = GlobalKey<FormState>();

  void login() {
    var loginForm = loginKey.currentState;
    if (loginForm.validate()) {
      loginForm.save();
      print("username:");
    }
  }

  @override
  Widget buildContent(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(15),
      child: Form(
          key: loginKey,
          child: Column(
            children: <Widget>[
              TextFormField(
                decoration: InputDecoration(labelText: '请输入用户名'),
                onSaved: (value) {
                  username = value;
                },
              ),
              TextFormField(
                decoration: InputDecoration(labelText: '请输入密码'),
                obscureText: true,
                validator: (value) {
                  return value.length < 6 ? "密码长度不够6位" : null;
                },
                onSaved: (value) {
                  pwd = value;
                },
              ),
              SizedBox(
                width: 340,
                height: 42,
                child: RaisedButton(
                  onPressed: login,
                  child: Text(
                    '登录',
                    style: TextStyle(fontSize: 18),
                  ),
                ),
              )
            ],
          )),
    );
  }

  @override
  String getTitle() {
    return '表单';
  }
}
